package com.study.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.study.bean.Attributevalue;
import com.study.bean.Camid;
import com.study.bean.Firstbrands;
import com.study.bean.Firstgoods;
import com.study.bean.Sort;
import com.study.biz.Attributevaluebiz;
import com.study.biz.Camidbiz;
import com.study.biz.Firstbandsbiz;
import com.study.biz.Firstgoodsbiz;
import com.study.biz.Sortbiz;
import com.study.dao.Firstgoodsdao;
import com.study.util.CommonUtils;
import com.study.util.Pager;

/**
 * Servlet implementation class classpageservlet
 */
@WebServlet("/classpage")
public class classpageservlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private Firstgoodsbiz biz = new Firstgoodsbiz();
	private Firstbandsbiz bizs = new Firstbandsbiz();

	@Override
	public String excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub

		// 鏍规嵁鍟嗗搧id鏌ヨ
		/*
		 * List<Firstgoods> morcha=biz.goodsid(); System.out.println("鍟嗗搧鏈�"+morcha);
		 * session.setAttribute("morcha",morcha);
		 */
		return "f:classpage";
	}

	// 默认查询(包括模糊查询和类别lid查询)
	public String idmor(HttpServletRequest request, HttpServletResponse response) {
		String v = "idmor";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String cname = request.getParameter("cname");
		request.setAttribute("color", 2);
		if (cname != null && !cname.equals("")) {
			request.setAttribute("cname", cname);
			System.out.println(cname + "价格查询模糊查询的名字时");
			//
			List<Firstgoods> list = biz.gnamemohus(cname, pageNo, pageSize);
			System.out.println(list.size());
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.likenameCount(cname), pageSize, list);
			// session.setAttribute("none", 1);
			request.setAttribute("morcha", morcha);
			return "f:classpage";

		} else {
			
			Sortbiz sbiz = new Sortbiz();
			String cid = request.getParameter("lid");
			System.out.println("lid是" + cid);
			Integer cids = Integer.parseInt(cid);
			List<Sort> sortlistzile = sbiz.selectSort(cids);
			System.out.println(sortlistzile);
			// session.removeAttribute("none");
			session.setAttribute("sortlists", sortlistzile);

			List<Firstgoods> list = biz.goodsfuji(cids, pageNo, pageSize);
			System.out.println("数据是" + list.size());
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.lidall(cids), pageSize, list);
			request.setAttribute("morcha", morcha);
			return "f:classpage";
		}

	}

	// 价格查询(包括模糊查询和类别lid查询)
	public String prices(HttpServletRequest request, HttpServletResponse response) {
		String v = "prices";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String cname = request.getParameter("cname");
		request.setAttribute("colors", 3);
		if (cname != null && !cname.equals("")) {
			request.setAttribute("cname", cname);
			System.out.println(cname + "价格查询模糊查询的名字时");
			//
			List<Firstgoods> list = biz.priceshuan(cname, pageNo, pageSize);
			System.out.print(list);
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.priceall(cname), pageSize, list);
			request.setAttribute("morcha", morcha);
			return "f:classpage";
		} else {
			String lids = request.getParameter("lid");
			Integer lid = Integer.parseInt(lids);
			request.setAttribute("lid", lid);
			System.out.println("lid是" + lid);
			System.out.println("数量是" + biz.countpone(lid));

			List<Firstgoods> list = biz.pricshualid(lid, pageNo, pageSize);
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.countprlid(lid), pageSize, list);
			request.setAttribute("morcha", morcha);
			return "f:classpage";
		}

	}

	// 根据类别id价格查询（倒序）
	public String pricedao(HttpServletRequest request, HttpServletResponse response) {
		String v = "pricedao";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}

		request.setAttribute("daolid", 3);
		String cname = request.getParameter("cname");
		if (cname != null && !cname.equals("")) {
			request.setAttribute("cname", cname);
			System.out.println(cname + "价格查询模糊查询的名字时");
			//
			List<Firstgoods> list = biz.priceshuan(cname, pageNo, pageSize);
			System.out.print(list);
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.priceall(cname), pageSize, list);
			request.setAttribute("morcha", morcha);
			return "f:classpage";
		} else {
			String lids = request.getParameter("lid");
			Integer lid = Integer.parseInt(lids);
			request.setAttribute("lid", lid);
			System.out.println("lid是" + lid);
			System.out.println("数量是" + biz.countpone(lid));
	
			List<Firstgoods> list = biz.pricdao(lid, pageNo, pageSize);
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.countprlid(lid), pageSize, list);
			request.setAttribute("morcha", morcha);
			return "f:classpage";
		}
	}

	// 查询最新商品（模糊查询和根据类别lid查询）
	public String zuinews(HttpServletRequest request, HttpServletResponse response) {
		String v = "zuinews";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String cname = request.getParameter("cname");
		System.out.println(cname + "名字时");
		request.setAttribute("colornew", 4);
		if (cname != null && !cname.equals("")) {
			request.setAttribute("cname", cname);
			List<Firstgoods> list = biz.goodnewsfen(cname, pageNo, pageSize);
			System.out.println("我进入了模糊查询");
			System.out.println(list.size());
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.newcount(cname), pageSize, list);
			request.setAttribute("morcha", morcha);
			String lids = request.getParameter("lid");
			return "f:classpage";
		} else {
			String lids = request.getParameter("lid");
			Integer lid = Integer.parseInt(lids);
			request.setAttribute("lid", lid);
			System.out.println("lid是" + lid);
			System.out.println("数量是" + biz.countpone(lid));

			List<Firstgoods> list = biz.zuinewlid(lid, pageNo, pageSize);
			Pager<Firstgoods> morcha = new Pager(pageNo, biz.countnewslid(lid), pageSize, list);
			request.setAttribute("morcha", morcha);
			return "f:classpage";
		}
	}

	// 查询所有子类
	public String zilei(HttpServletRequest request, HttpServletResponse response) {
		Sortbiz sbiz = new Sortbiz();
		String cid = request.getParameter("cid");
		System.out.println("瀛愮被閲岄潰鏁板瓧鏄�" + cid);
		Integer cids = Integer.parseInt(cid);
		List<Sort> sortlistzile = sbiz.selectSort(cids);
		System.out.println(sortlistzile);
		session.removeAttribute("none");
		request.setAttribute("sortlists", sortlistzile);
		return "f:classpage";
	}

	// 根据类别lid 查询康佳
	public String brandkj(HttpServletRequest request, HttpServletResponse response) {
		String v = "brandkj";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("brandone", 1);

		List<Firstbrands> list = bizs.brandskjlid(lid, pageNo, pageSize);
		Pager<Firstbrands> morcha = new Pager(pageNo, bizs.countkjia(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

	// 根据类别lid 查询kktv
	public String brandkktv(HttpServletRequest request, HttpServletResponse response) {
		String v = "brandkktv";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("brandtwo", 2);

		List<Firstbrands> list = bizs.brandskktvlid(lid, pageNo, pageSize);
		Pager<Firstbrands> morcha = new Pager(pageNo, bizs.countkktv(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}
	
	
	//价格不限查询（查询所有商品）
	public String nolimit(HttpServletRequest request, HttpServletResponse response) {
		String v = "nolimit";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("nolimit", 9);

		List<Firstgoods> list = biz.goodsidall(lid,pageNo, pageSize);
		Pager<Firstbrands> morcha = new Pager(pageNo, biz.nolimit(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}
	//品牌不限查询（查询所有商品）
	public String nolimitbrand(HttpServletRequest request, HttpServletResponse response) {
		String v = "nolimitbrand";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("nolimitb", 10);

		List<Firstgoods> list = biz.goodsidall(lid,pageNo, pageSize);
		Pager<Firstbrands> morcha = new Pager(pageNo, biz.nolimit(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}
	
	

	// 价格区间查询
	public String priceone(HttpServletRequest request, HttpServletResponse response) {
		String v = "priceone";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("styleone", 1);

		System.out.println("lid是" + lid);
		System.out.println("数量是" + biz.countpone(lid));

		List<Firstgoods> list = biz.jiange1(lid, pageNo, pageSize);
		Pager<Firstgoods> morcha = new Pager(pageNo, biz.countpone(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

	public String pricetwo(HttpServletRequest request, HttpServletResponse response) {
		String v = "pricetwo";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("styletwo", 2);

		List<Firstgoods> list = biz.jiang2(lid, pageNo, pageSize);
		Pager<Firstgoods> morcha = new Pager(pageNo, biz.countptwo(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

	public String pricethree(HttpServletRequest request, HttpServletResponse response) {
		String v = "pricethree";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}

		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("stylethree", 3);
		List<Firstgoods> list = biz.jiange3(lid, pageNo, pageSize);
		Pager<Firstgoods> morcha = new Pager(pageNo, biz.countpthree(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

	public String pricefour(HttpServletRequest request, HttpServletResponse response) {
		String v = "pricefour";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("stylefour", 4);

		List<Firstgoods> list = biz.jiange4(lid, pageNo, pageSize);
		Pager<Firstgoods> morcha = new Pager(pageNo, biz.countpfour(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

	public String pricefive(HttpServletRequest request, HttpServletResponse response) {
		String v = "pricefive";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		String lids = request.getParameter("lid");
		Integer lid = Integer.parseInt(lids);
		request.setAttribute("lid", lid);
		// 样式用
		request.setAttribute("stylefive", 5);

		List<Firstgoods> list = biz.jiange5(lid, pageNo, pageSize);
		Pager<Firstgoods> morcha = new Pager(pageNo, biz.countfive(lid), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

	// 模糊查询（默认）
	public String selectnamemohu(HttpServletRequest request, HttpServletResponse response) {
		String cname = request.getParameter("cname");
		request.setAttribute("cname", cname);
		String v = "selectnamemohu";
		request.setAttribute("method", v);
		int pageNo = 1;
		int pageSize = 4;
		String no = request.getParameter("pageno");
		if (CommonUtils.verifyInteger(no)) {
			pageNo = Integer.parseInt(no);
		}
		List<Firstgoods> list = biz.gnamemohus(cname, pageNo, pageSize);
		System.out.println(list.size());
		Pager<Firstgoods> morcha = new Pager(pageNo, biz.likenameCount(cname), pageSize, list);
		session.setAttribute("none", 1);
		request.setAttribute("mohu", 5);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

	// 属性查询
	public String addguigecomm(HttpServletRequest request, HttpServletResponse response) {
		// 鏌ヨ灞炴��
		Camidbiz camidbiz = new Camidbiz();
		List<Camid> camlist = camidbiz.selectbyId(0);
		// 鏌ヨ灞炴�у�紇alue
		Attributevaluebiz attvaluebiz = new Attributevaluebiz();
		for (Camid c : camlist) {
			List<Attributevalue> attvalue = attvaluebiz.attvaluelist(c.getAttid());
			c.setAttvalueslist(attvalue);
		}
		request.setAttribute("camlist", camlist);
		return "f:classpage";
	}

	// 根据父级id查询所有的商品(默认)
	public String fujiallgoods(HttpServletRequest request, HttpServletResponse response) {
		String v = "fujiallgoods";
		request.setAttribute("method", v);
		Sortbiz sbiz = new Sortbiz();
		String cid = request.getParameter("lid");
		System.out.println("lid是" + cid);
		Integer cids = Integer.parseInt(cid);
		List<Sort> sortlistzile = sbiz.selectSort(cids);
		String lname = sbiz.lids(cids).getLname();
		System.out.println(sortlistzile);
		
		String mbstr="";
		String zi=request.getParameter("zi");
		if(zi==null||"".equals(zi)) {
			mbstr=lname;
		}else {
			Object str=session.getAttribute("lname");
			mbstr=str.toString()+"  >   "  +lname;
		}
		System.out.print("面包屑："+mbstr);
		
		session.removeAttribute("none");
		session.setAttribute("lname", mbstr);
		session.setAttribute("sortlists", sortlistzile);
		request.setAttribute("lidcol", 6);
		int pageNo = 1;
		int pageSize = 4;
		List<Firstgoods> list = biz.goodsfuji(cids, pageNo, pageSize);
		System.out.println("数据是" + list.size());
		Pager<Firstgoods> morcha = new Pager(pageNo, biz.lidall(cids), pageSize, list);
		request.setAttribute("morcha", morcha);
		return "f:classpage";
	}

}
